<?php

class cron extends Module {
	
	public function __construct () {
		parent::__construct (__CLASS__);
		
		$this->extend ('__custom_cron');
	}
	
	public function __default () {
		$accessKey = getRequest ('accesskey');
		if ($accessKey != Regedit::getInstance()->get ('//modules/cron/access_key')) {
			exit ('key invalid');
		}
		
		$callModule = getRequest ('module');
		if (!mb_strlen ($callModule)) {
			exit ('module not defined');
		}
		
		$callMethod = getRequest ('method');
		if (!mb_strlen ($callMethod)) {
			$callMethod = '__default';
		}
		
		$cronFile = ENGINE_ROOT . '/modules/' . $callModule . '/cron.php';
		
		if (!file_exists ($cronFile)) {
			exit ('module cron file not founded');		
		}
		
		include $cronFile;
		
		$className = $callModule . '_cron';
		
		if (!class_exists ($className)) {
			exit ('cron class not exists');
		}
		
		$oCron = new $className;
		
		if (!method_exists ($oCron, $callMethod)) {
			exit ('method not exists');
		}
		
		eval ('$oCron->' . $callMethod . ' ();');
		
		exit ('1');
	}	
}